package cn.itcast.flink.window.time;
import org.apache.flink.streaming.api.TimeCharacteristic;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
* 滚动事件时间窗口（Tumbling EventTime Window）统计：每隔5秒，计算5秒内，每个用户的订单金额
* TODO：添加Watermark水位线，来解决一定程度上的数据延迟和数据乱序问题
*/
public class StreamEventTimeWatermarkWindow_6 {
public static void main(String[] args) throws Exception {
// 1. 执行环境-env
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
env.setParallelism(1);
// TODO: 设置基于事件时间EventTime窗口
env.setStreamTimeCharacteristic(TimeCharacteristic.EventTime);
// 2. 数据源-source
DataStreamSource<Order> orderStream = env.addSource(new OrderSource());
//orderStream.printToErr();
// TODO： 指定事件时间EventTime字段和设置水位线

// TODO: 设置最大延迟数据时间为2秒

// 5. 触发执行-execute
env.execute(StreamEventTimeWatermarkWindow_6.class.getSimpleName());
    }
}